package com.atguigu01._static;

/**
 * ClassName: PersonTest
 * Description:
 *
 * @Author liu
 * @Create 2024/10/31 23:14
 * @Version 1.0
 */
public class chineseTest {
    public static void main(String[] args) {
        System.out.println(Chinese.nation);
        Chinese.show();

        Chinese c1 = new Chinese();
        c1.name = "姚明";
        c1.age = 40;
        c1.nation = "China";

        Chinese c2 = new Chinese();
        c2.name = "刘翔";
        c2.age = 39;

        System.out.println(c1);
        System.out.println(c2);

        System.out.println(c1.nation);//China
        System.out.println(c2.nation);//China

        c2.nation = "CHN";

        System.out.println(c1.nation);//CHN
        System.out.println(c2.nation);//CHN

        c1.show();



    }

}
class Chinese{
    //非静态变量，实例变量
    //只有创建对象后，才运行
   String name;
   int age;

    // 静态变量，类变量
    // 可以直接调用,多个对象可调用一个静态类变量，只调用一次
    // Chinese.nation
   static String nation="中国";


    @Override
    public String toString() {
        return "Chinese{" +
                "name='" + name + '\'' +
                ", age=" + age +
                '}';
    }


    //非静态方法
    public void eat(){
        System.out.println("lllll");
    }

    //静态方法
    public static void show(){
        System.out.println("kkkkk");

        //可以调用静态的结构
        System.out.println("nature: "+ Chinese.nation);
        method1();
        //不可以调用非静态方法
//        System.out.println("age"+age);
//        method2();
    }


    public static void method1(){
        System.out.println("静态方法");
    }

    //非静态变量
    //可以调用非静态与静态方法
    public void method2(){
        System.out.println("非静态方法");

        //可以调用静态的结构
        System.out.println("nature"+ Chinese.nation);
        method1();
        //不可以调用非静态方法
        System.out.println("age"+age);
        method2();
    }

}